package com.jz.community.commview.view;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jz.community.commview.R;

public class MyStateView {

    private View noDataView;
    private View errorView;
    private View loadingView;
    private View locationView;


    public View getNoDataView(Activity context, ViewGroup viewGroup, String text, View.OnClickListener listener) {
        noDataView = context.getLayoutInflater().inflate(R.layout.view_empty, viewGroup, false);
        ImageView empty_iv = noDataView.findViewById(R.id.empty_img);
        TextView empty_tv = noDataView.findViewById(R.id.empty_tv);
        empty_iv.setImageResource(R.mipmap.empty_default);
        empty_tv.setText(text);
        empty_tv.setOnClickListener(listener);
        return noDataView;
    }

    public View getErrorView(Activity context, ViewGroup viewGroup, View.OnClickListener listener) {
        errorView = context.getLayoutInflater().inflate(R.layout.view_error, viewGroup, false);
        ImageView error_iv = errorView.findViewById(R.id.error_img);
        error_iv.setImageResource(R.mipmap.error_default);
        errorView.setOnClickListener(listener);
        return errorView;
    }

    public View getLoadingView(Activity context, ViewGroup viewGroup, int drawable) {
        loadingView = context.getLayoutInflater().inflate(R.layout.view_loading, viewGroup, false);
        ImageView loading_iv = loadingView.findViewById(R.id.loading_img);
        Glide.with(context)
                .asGif()
                .load(drawable)
                .into(loading_iv);
        return loadingView;
    }

    public View getLocationView(Activity context, ViewGroup viewGroup, View.OnClickListener locbtn1, View.OnClickListener locbtn2) {
        locationView = context.getLayoutInflater().inflate(R.layout.view_empty_loc, viewGroup, false);
        TextView empty_loc_btn1 = locationView.findViewById(R.id.empty_loc_btn1);
        TextView empty_loc_btn2 = locationView.findViewById(R.id.empty_loc_btn2);
        empty_loc_btn1.setOnClickListener(locbtn1);
        empty_loc_btn2.setOnClickListener(locbtn2);
        return locationView;
    }
}
